<template>
  <div>
    <el-row>
      <el-button
        size="mini"
        type="primary"
        icon="el-icon-refresh-left"
        plain
        @click="openData"
        >刷新</el-button
      >
      <el-button
        size="mini"
        type="primary"
        icon="el-icon-refresh-left"
        plain
        @click="onAddCmsMenu"
        >增加菜单</el-button
      >
    </el-row>
    <div style="height: 15px"></div>
    <el-dialog v-model="FShowMenuEdit" center destroy-on-close>
      <TFormCmsMenuEdit
        :zContextParams="FIndexCmsMenu"
        :zContextOnCall="onCallBack"
      ></TFormCmsMenuEdit>
    </el-dialog>
    <el-table
      :data="FCmsMenuTreeList"
      row-key="FMenuID"
      border
      default-expand-all
      highlight-current-row
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="FTreeCode" label="树形代码"> </el-table-column>
      <el-table-column prop="FMenuName" label="菜单名称"> </el-table-column>
      <el-table-column prop="FMenuCmdMode" label="菜单命令"> </el-table-column>
      <el-table-column prop="FMenuCmdCode" label="菜单脚本"> </el-table-column>
      <el-table-column label="操作">
        <template #default="scope">
          <el-button type="primary" plain size="mini" @click="onEdit(scope.row)"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="danger"
            plain
            @click="onDesgin(scope.row)"
            >设计</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script lang="ts">
import {
  TBaseCmsMenu,
  TMyMenuCmdMode,
  TMyMenuCmdModeClass,
} from "@/baselib/module/cms/BaseCmsApi";
import TFormBase from "@/views/BaseForm";
import elmHelper from "../model/elmHelper";
import TFormCmsMenuEdit from "@/views/cms/CmsMenuEdit.vue";
import { Options } from "vue-class-component";
import { IMenuItem } from "@/store";
//配合着用
@Options({
  name: "TFormCmsMenu",
  components: {
    TFormCmsMenuEdit,
  },
  computed: {},
  data() {},
})
export default class TFormCmsMenu extends TFormBase {
  private FCmsMenuList: TBaseCmsMenu[] = [];
  private FCmsMenuTreeList: any[] = [];
  private FCmsID: string = "";
  private FIndexCmsMenu: TBaseCmsMenu = new TBaseCmsMenu();
  private FShowMenuEdit = false;
  public created() {
    this.FCmsID = this.zIndexTag?.menuParams.CMSID;
    if (this.$myStrHelper.stringIsEmptyYW(this.FCmsID)) {
      this.$myMsgHelp.msgDialog("传进来的参数 CMSID 不可为空");
      return;
    }
    this.openData();
  }
  private async openData() {
    let lResult = await this.$myBaseCms.GetCmsMenuList(this.FCmsID);
    if (!lResult.resultSuccess) {
      this.$myMsgHelp.msgDialog(lResult.resultMsg);
      return;
    }
    this.FCmsMenuList = lResult.resultData;
    //转化成树形结构
    this.FCmsMenuTreeList = elmHelper.dataAddchildren(
      this.FCmsMenuList,
      "FMenuID",
      "FPMenuID"
    );
    this.$myMsgHelp.msgHintAutoClose("打开数据成功");
  }
  private onAddCmsMenu() {
    this.FShowMenuEdit = true;
    this.FIndexCmsMenu = new TBaseCmsMenu();
    this.FIndexCmsMenu.FCMSID = this.FCmsID;
  }
  private onEdit(qMenu: TBaseCmsMenu) {
    this.FIndexCmsMenu = qMenu;
    this.FShowMenuEdit = true;
  }
  private onEditCallBack(cmdCode: string, qMenu: TBaseCmsMenu) {
    this.FShowMenuEdit = false;
    this.openData();
  }
  private onDesgin(qMenu: TBaseCmsMenu) {
    if (qMenu.FMenuCmdMode == TMyMenuCmdModeClass.document) {
      let lTag: IMenuItem = {
        menuIndexName: "TFormCmsEditor_" + qMenu.FMenuID,
        menuComponent: "TFormCmsEditor",
        menuTitle: "菜单设计_" + qMenu.FMenuName,
        menuIcon: "",
        menuParams: { CmsID: qMenu.FCMSID, CmsMenuID: qMenu.FMenuID }, //参数
        menuChildren: [],
      };
      this.$myEvenBus.addTag(lTag);
    } else if (qMenu.FMenuCmdMode == TMyMenuCmdModeClass.question) {
      let lTag: IMenuItem = {
        menuIndexName: "TFormCmsQuestionList_" + qMenu.FMenuID,
        menuComponent: "TFormCmsQuestionList",
        menuTitle: "菜单问题_" + qMenu.FMenuName,
        menuIcon: "",
        menuParams: { CmsMenu: qMenu }, //参数
        menuChildren: [],
      };
      this.$myEvenBus.addTag(lTag);
    } else {
      this.$myMsgHelp.msgDialog("未设计的指令【" + qMenu.FMenuCmdMode + "】");
    }
  }
  private onCallBack() {
    this.FShowMenuEdit = false;
    this.openData();
  }
}
</script>
